from apps.crm.models import Menu

def menu_info(request):
    # 查询一级菜单
    print(request.user.is_authenticated)
    if request.user.is_authenticated():
        # print(request.user.roles.all())
        roles = request.user.roles.all()
        q_menus = ""
        for role in roles:
            if q_menus:
                q_menus = q_menus | role.menus.all()
            else:
                q_menus = role.menus.all()
        print(q_menus)
        if q_menus:
                #去重
                q_menus = q_menus.distinct()
                menus = q_menus.filter(pid_menu=None)
                # 获取二级菜单
                for menu in menus:
                    menu.children_menus = q_menus.filter(pid_menu=menu.id)
                print(menus)
    else:
        menus=Menu.objects.filter(url_name__contains='index')
    print(menus)
    print('1'*40)
    return locals()
